package com.example.houqin_oa.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.comment_oa.pojos.DrawGoods;
import com.example.houqin_oa.mapper.EntrepotMapper;
import com.example.houqin_oa.mapper.PersonalEffectsMapper;
import com.example.houqin_oa.service.DrawGoodsService;
import com.example.houqin_oa.mapper.DrawGoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
* @author liang
* @description 针对表【draw_goods】的数据库操作Service实现
* @createDate 2022-10-24 17:14:29
*/
@Service
public class DrawGoodsServiceImpl extends ServiceImpl<DrawGoodsMapper, DrawGoods>
    implements DrawGoodsService{
    @Autowired
    DrawGoodsMapper drawGoodsMapper;

    @Autowired
    PersonalEffectsMapper personalEffectsMapper;

    @Autowired
    EntrepotMapper entrepotMapper;

    @Override
    public List<DrawGoods> DrawAll(DrawGoods drawGoods) {
        drawGoods.setDrawState("0");
        return drawGoodsMapper.DrawAll(drawGoods);
    }

    @Override
    public List<DrawGoods> Open(DrawGoods drawGoods) {
        return drawGoodsMapper.Open(drawGoods);
    }

    @Override
    public boolean AddModify(DrawGoods drawGoods) {
        boolean Thing ;
        boolean Modify ;
        boolean Store;
        Date d = new Date();

        SimpleDateFormat sbf = new SimpleDateFormat("yyyyMMddHHmmss");
        drawGoods.setDrawGoodsNo("LQ"+sbf.format(d));
        drawGoods.setDrawState("0");
        drawGoods.setDrawTime(d);
        //新增个人物品
        Thing = personalEffectsMapper.AddThing(drawGoods);

        drawGoods.setDrawState("1");
        //新增个人物品领取记录
        Modify = drawGoodsMapper.AddModify(drawGoods);

        //修改仓库数量
        Store = entrepotMapper.Polish(drawGoods);


        if(Thing && Modify && Store){
            return true;
        }else {
            return false;
        }

    }

    @Override
    public List<DrawGoods> Note(DrawGoods drawGoods) {
        return drawGoodsMapper.Note(drawGoods);
    }
}




